package com.yuxue.util;

import com.yuxue.constant.Constant;
import org.apache.commons.io.filefilter.AbstractFileFilter;
import org.apache.commons.io.filefilter.FileFileFilter;
import org.apache.commons.io.filefilter.IOFileFilter;

import java.io.File;
import java.io.Serializable;

public class ImgFileFilter extends AbstractFileFilter implements Serializable {

    private static final long serialVersionUID = 5345244090827540862L;
    /** Singleton instance of file filter */
    public static final IOFileFilter FILE = new ImgFileFilter();

    /**
     * Restrictive constructor.
     */
    ImgFileFilter() {
    }

    /**
     * Checks to see if the file is a file.
     *
     * @param file  the File to check
     * @return true if the file is a file
     */
    @Override
    public boolean accept(final File file) {
        String name = file.getName().toLowerCase();
        String format = name.substring(name.lastIndexOf(".") + 1);
        if (Constant.DEFAULT_TYPE.contains(format)) {
            return true;
        } else {
            return false;
        }
    }

}
